package demo

import (
	"bytes"
	_ "embed"
	"fmt"
	"net/http"
	"os/exec"
)

//go:embed \test.html
var HtmlPlay []byte

func Rtsp() {

	http.HandleFunc("/index", func(writer http.ResponseWriter, request *http.Request) {
		writer.Write([]byte(HtmlPlay))
	})
	http.Handle("/", http.FileServer(http.Dir(".")))
	go func() {
		http.ListenAndServe(":9000", nil)
	}()
	cmd := exec.Command("ffmpeg", "-i", "rtsp://admin:admin@40.40.40.101/media/video1", "-c", "copy", "-f", "hls", "-hls_time", "2.0", "-hls_list_size", "0", "-hls_wrap", "15", "./test.m3u8")
	var out bytes.Buffer
	var stderr bytes.Buffer
	cmd.Stdout = &out
	cmd.Stderr = &stderr
	err := cmd.Run()
	if err != nil {
		fmt.Println(fmt.Sprint(err) + ": " + stderr.String())
		return
	}
	fmt.Println("Result: " + out.String())
}
